import json
from glob import glob

if __name__ == '__main__':
    data_dir = "/home/HDD/linzihao/datasets/liantong/CPRI/cpri/cpri/all_data"
    # out_dir = "/home/HDD/linzihao/cpri_equipcheck/data_prepare/annotation_1"
    json_list = glob(data_dir + "/*.json")

    for ind, json_file in enumerate(json_list):
        with open(json_file, 'r') as f:
            data = json.load(f)

        if "shapes" not in data.keys():
            continue

        height = data["imageHeight"]
        width = data["imageWidth"]

        items = data["shapes"]
        for item in items:
            points = item["points"]
            x1, y1 = points[0]
            x2, y2 = points[1]
            assert x1 < x2
            assert y1 < y2
            assert x2 <= width, f"width: {width}, x2: {x2}"
            assert y2 <= height, f"height: {height}, y2: {y2}"           
